#define _CRT_SECURE_NO_WARNINGS 1
int removeElement(int* nums, int numsSize, int val)
{
    int flag = 0;
    int i;
    for (i = 0; i < numsSize; i++)
    {
        if (nums[i] != val)
            nums[flag++] = nums[i];
    }
    return flag;
}

int removeDuplicates(int* nums, int numsSize)
{
    int flag = 0;
    int i;
    for (i = 1; i < numsSize; i++)
    {
        if (nums[i] != nums[flag])
            nums[++flag] = nums[i];
    }
    return flag + 1;
}

void merge(int* nums1, int nums1Size, int m, int* nums2, int nums2Size, int n)
{
    int p1 = m - 1, p2 = n - 1;
    int k = m + n - 1, tmp;
    while (p1 >= 0 || p2 >= 0)
    {
        if (p1 == -1)
            tmp = nums2[p2--];
        else if (p2 == -1)
            tmp = nums1[p1--];
        else if (nums1[p1] > nums2[p2])
            tmp = nums1[p1--];
        else
            tmp = nums2[p2--];
        nums1[k--] = tmp;
    }
}